
#include "info.h"
#include <cassert>
#define ASSERT_ENABLE

EInfoType Info::getType()
{
	return type;
}


Info::Info(bool _b)
	: type(itBool), boolValue(_b), source(isReal)
{
}


Info::Info(int _i)
	: type(itInt), intValue(_i), source(isReal)
{
}


Info::Info(float _f)
	: type(itFloat), floatValue(_f), source(isReal)
{
}

Info::~Info()
{
	/* nothing to do yet... */
}

void Info::set(bool _b)
{
	type = itBool;
	boolValue = _b;
}


void Info::set(int _i)
{
	type = itInt;
	intValue = _i;
}


void Info::set(float _f)
{
	type = itFloat;
	floatValue = _f;
}


inline bool& Info::b()
{
	#ifdef ASSERT_ENABLE
	assert(type == itBool);
    #endif
	return boolValue;
}

inline int& Info::i()
{
	#ifdef ASSERT_ENABLE
	assert(type == itInt);
    #endif
	return intValue;
}

inline float& Info::f()
{
	#ifdef ASSERT_ENABLE
	assert(type == itFloat);
    #endif
	return floatValue;
}

/* tostream... */
void Info::toStream(std::ostream& os, unsigned int indent, ESerializationType sertype) const
{
	os << '<';
	switch(source)
	{
	case isReal:
		os << "REAL: ";
 		break;
	case isSense:
		os << "SENSE: ";
 		break;
 	default:
 		os << "other source: ";
 		break;
	}
	
	switch(type)
	{
	case itBool:
		os << "bool " << boolValue;
		break;
	case itInt:
		os << "int " << intValue;
		break;
	case itInfoId:
		os << "iid XXXXXX";// << boolValue;
		break;
	case itFloat:
		os << "float " << floatValue;
		break;
	case itString:
		os << "string XXXXXX";//<" << boolValue << ">";
		break;
	default:
		break;
	}
	os << '>';
}

std::ostream& operator<<(std::ostream& os, const Info& info)
{
	info.toStream(os,0,stFull);
	return os;
}

